package com.heavenbird.common.util;

import java.sql.Timestamp;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class DBUtil {
	private static transient Log log = LogFactory.getLog(DBUtil.class);
	
	private static SessionFactory sessionFactory;

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public static void setSessionFactory(SessionFactory sessionFactory) {
		DBUtil.sessionFactory = sessionFactory;
	}

	public static Session getSession() {
		return sessionFactory.getCurrentSession();
	}
	
	public static Timestamp getSysDate() {
		Session session = sessionFactory.getCurrentSession();
		SQLQuery query = session.createSQLQuery("select now() from dual");
		List<Timestamp> list = query.list();
		Timestamp now = list.get(0);
		return now;
	}
}
